home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / comm / avm / rexx / handledata.avm < prev    next >
Encoding:
Text File  |  1994-04-06  |  11.1 KB  |  458 lines

  1. /* TITLE: avm:source/handledata.avmsrc */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse arg servername mailbox .
  23. if symbol('mailbox') ~= 'VAR' | mailbox = '' then mailbox = 'manual'
  24.  
  25. 'requiremode' 'Connected'
  26.  
  27. 'turnoffvoicemode'
  28.  
  29. 'assumemode' 'Unknown'
  30.  
  31. 'writeline' 'ATA'
  32. 'readline' '90'
  33. action = rc
  34. select
  35.   when action = 0 then nop
  36.   when action = 10 then signal answerdataabort
  37.   when action = 12 then signal answerdataabort
  38.   when action = 14 then signal stderror
  39.   when action = 16 then signal stderror
  40.   otherwise signal arexxerror
  41. end
  42.  
  43. 'readline' '90'
  44. action = rc
  45. if action = 0 then value = result
  46. select
  47.   when action = 0 then nop
  48.   when action = 10 then signal answerdataabort
  49.   when action = 12 then signal answerdataabort
  50.   when action = 14 then signal stderror
  51.   when action = 16 then signal stderror
  52.   otherwise signal arexxerror
  53. end
  54.  
  55. if (left(value, 7) = 'CONNECT') then do
  56.   address rexx 'startbbs' value
  57. end
  58.  
  59. finished:
  60. do forever
  61.  
  62. 'readline' '2'
  63. action = rc
  64. if action = 0 then value = result
  65. select
  66.   when action = 0 then nop
  67.   when action = 10 then signal answerabortreadall
  68.   when action = 12 then signal stdabort
  69.   when action = 14 then signal stderror
  70.   when action = 16 then signal stderror
  71.   otherwise signal arexxerror
  72. end
  73.  
  74. end
  75.  
  76. answerabortreadall:
  77. exit
  78.  
  79. answerdataabort:
  80. 'writeline' 'A'
  81. signal finished
  82.  
  83. /* TITLE: avm:source/simplestdtail.avmsrc */
  84. /* This is the standard tail */
  85. exit
  86.  
  87. exit
  88.  
  89. mailboxDir: procedure
  90.     parse arg mailbox
  91.  
  92.     return 'avm:' || mailbox || '/'
  93.  
  94. logFile: procedure
  95.     parse arg mailbox, magiccookie
  96.  
  97.     return 'avm:' || mailbox || '/logs/' || magiccookie
  98.  
  99. voiceFile: procedure
  100.     parse arg mailbox, magiccookie
  101.  
  102.         if (verify(magiccookie, '/:', 'M') = 0) then
  103.           return 'avm:' || mailbox || '/voices/' || magiccookie
  104.         else
  105.           return magiccookie
  106.  
  107. makeUniqueFile: procedure
  108.     if arg() ~= 0 then do
  109.         rc = "makeUniqueFile: bad args"
  110.         signal error
  111.     end
  112.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  113.  
  114. convertToDate: procedure
  115.     if arg() ~= 1 then do
  116.         rc = "convertToDate: bad args"
  117.         signal error
  118.     end
  119.     parse arg timeInC
  120.  
  121.     actualTime = (timeInC - (2922)*86400) // (86400)
  122.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  123.  
  124.     return actualDate /* returning it in 'internal' format */
  125.  
  126. convertToTime: procedure
  127.     if arg() ~= 1 then do
  128.         rc = "convertToTime: bad args"
  129.         signal error
  130.     end
  131.     parse arg timeInC
  132.     
  133.     actualTime = (timeInC - (2922)*86400) // (86400)
  134.  
  135.     return actualTime
  136.  
  137. cTime: procedure
  138.     /* 2922 = 8*365 + 2 */
  139.     /* 86400 = 24*60*60 */
  140.     return (date('i')+2922)*86400 + time('s')
  141.  
  142. /* this returns a handle that you must use after initializing log. */
  143. initLogEntry: procedure expose log.
  144.     if arg() ~= 0 then do
  145.         rc = "initLogEntry: bad args"
  146.         signal error
  147.     end
  148.     
  149.     drop log.
  150.         log. = ''
  151.  
  152.         acidname = getclip(address() || 'CIDNAME')
  153.         acidnumber = getclip(address() || 'CIDNUMBER')
  154.  
  155.     /* 2922 = 8*365 + 2 */
  156.     /* 86400 = 24*60*60 */
  157.     log.time = (date('i')+2922)*86400 + time('s')
  158.     log.cidname = acidname
  159.     log.cidnumber = acidnumber
  160.  
  161.     return
  162.  
  163. loadLogEntry: procedure expose log.
  164.     if arg() ~= 2 then do
  165.         rc = "loadLogEntry: bad args"
  166.         signal error
  167.     end
  168.     parse arg mailbox, handle
  169.  
  170.         drop log.
  171.         log. = ''
  172.  
  173.     if ~exists(mailboxDir(mailbox)) then do
  174.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  175.         return
  176.     end
  177.  
  178.     opened = open(handle, logFile(mailbox, handle), 'r')
  179.         if opened then do
  180.         call showDebugger('Loading entry' logFile(mailbox, handle))
  181.         do while ~eof(handle)
  182.             line = readln(handle)
  183.             parse upper var line variable '=' value
  184.             log.variable = value
  185.         end
  186.         call close(handle)
  187.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  188.     return
  189.  
  190. /* pass a handle here */
  191. saveLogEntry: procedure expose log.
  192.     if arg() ~= 2 then do
  193.         rc = "saveLogEntry: bad args"
  194.         signal error
  195.     end
  196.     parse arg mailbox, handle
  197.  
  198.     if ~exists(mailboxDir(mailbox)) then do
  199.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  200.         return
  201.     end
  202.  
  203.     opened = open(handle, logFile(mailbox, handle), 'w')
  204.  
  205.     if opened then do
  206.         call showDebugger('Saving entry' logFile(mailbox, handle))
  207.         call writeln(handle, 'TYPE=' || log.type)
  208.         call writeln(handle, 'TIME=' || log.time)
  209.         call writeln(handle, 'LENGTH=' || log.length)
  210.  
  211.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  212.  
  213.         call writeln(handle, 'CIDNAME=' || log.cidname)
  214.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  215.  
  216.         call writeln(handle, 'COMMENT=' || log.comment)
  217.  
  218.         call writeln(handle, 'FILENAME=' || log.filename)
  219.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  220.  
  221.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  222.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  223.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  224.  
  225.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  226.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  227.  
  228.         call close(handle)
  229.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  230.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  231.  
  232.     return
  233.  
  234. /* pass a handle here */
  235. updateLogEntry: procedure expose log.
  236.     if arg() ~= 2 then do
  237.         rc = "updateLogEntry: bad args"
  238.         signal error
  239.     end
  240.     parse arg mailbox, handle
  241.  
  242.     if ~exists(mailboxDir(mailbox)) then do
  243.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  244.         return
  245.     end
  246.  
  247.     if ~exists(logFile(mailbox, handle)) then do
  248.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  249.         return
  250.     end
  251.     opened = open(handle, logFile(mailbox, handle), 'w')
  252.  
  253.     if opened then do
  254.         call showDebugger('Updating entry' logFile(mailbox, handle))
  255.         call writeln(handle, 'TYPE=' || log.type)
  256.         call writeln(handle, 'TIME=' || log.time)
  257.         call writeln(handle, 'LENGTH=' || log.length)
  258.  
  259.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  260.  
  261.         call writeln(handle, 'CIDNAME=' || log.cidname)
  262.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  263.  
  264.         call writeln(handle, 'COMMENT=' || log.comment)
  265.  
  266.         call writeln(handle, 'FILENAME=' || log.filename)
  267.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  268.  
  269.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  270.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  271.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  272.  
  273.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  274.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  275.  
  276.         call close(handle)
  277.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  278.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  279.  
  280.     return
  281.  
  282.  
  283.  
  284. showDebugger: procedure
  285.     if arg() ~= 1 then do
  286.         say "showDebugger: ERROR"
  287.         exit 20
  288.     end
  289.  
  290.     parse arg debuggerInfo
  291.     
  292.     firstLine = sourceline(1)
  293.     parse var firstLine '/*' 'TITLE:' title '*/'
  294.     if showlist('p', 'AVMLOGGER') then
  295.         address 'AVMLOGGER' 'add' title ':' debuggerInfo
  296.     else
  297.         say title ':' debuggerInfo
  298.  
  299.     return 
  300.  
  301. /*-----------------------------------------------------------------------*/
  302. /*                         signal processing                             */
  303.  
  304. arexxerror:
  305. error:
  306.     call showDebugger("Error" rc "at line" sigl)
  307.     exit 20
  308.  
  309. break_c:
  310. halt:
  311.     call showDebugger("Halt/Break_C at line" sigl)
  312.     exit 20
  313.  
  314. novalue:
  315.     call showDebugger("No value at line" sigl)
  316.     exit 20
  317.  
  318. syntax:
  319.     call showDebugger("Syntax error" rc "at line" sigl)
  320.     exit 20
  321.  
  322. exit
  323.  
  324. /* this requires logfunctions.avm */
  325.  
  326. loadMailbox: procedure expose mailbox.
  327.     if arg() ~= 1 then do
  328.         rc = "loadMailbox: bad args"
  329.         signal error
  330.     end
  331.  
  332.         mailbox. = ''
  333.     parse arg mailbox
  334.  
  335.     handle = 'mailboxconfig'
  336.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'r')
  337.     if opened then do
  338.         do while ~eof(handle)
  339.             line = readln(handle)
  340.             parse upper var line variable '=' value
  341.             mailbox.variable = value
  342.         end
  343.         call close(handle)
  344.     end
  345.     return
  346.  
  347. /* pass a handle here */
  348. saveMailbox: procedure expose mailbox.
  349.     if arg() ~= 1 then do
  350.         rc = "saveMailbox: bad args"
  351.         signal error
  352.     end
  353.     parse arg mailbox
  354.  
  355.     handle = 'mailboxconfig'
  356.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'w')
  357.  
  358.     if opened then do
  359.         call writeln(handle, 'PASSWORD=' || mailbox.password)
  360.  
  361.         call writeln(handle, 'AUTOFAXFORWARDB=' || mailbox.autofaxforwardb)
  362.         call writeln(handle, 'AUTOFAXFORWARD=' || mailbox.autofaxforward)
  363.         call writeln(handle, 'AUTOFAXFORWARDSCRIPT=' || mailbox.autofaxforwardscript)
  364.  
  365.         call writeln(handle, 'AUTOFORWARDB=' || mailbox.autoforwardb)
  366.         call writeln(handle, 'AUTOFORWARDONDEMAND=' || mailbox.autoforwardondemand)
  367.         call writeln(handle, 'AUTOFORWARD=' || mailbox.autoforward)
  368.         call writeln(handle, 'AUTOFORWARDSCRIPT=' || mailbox.autoforwardscript)
  369.  
  370.         call writeln(handle, 'AUTOPAGEB=' || mailbox.autopageb)
  371.         call writeln(handle, 'AUTOPAGEONDEMAND=' || mailbox.autopageondemand)
  372.         call writeln(handle, 'AUTOPAGE=' || mailbox.autopage)
  373.         call writeln(handle, 'AUTOPAGESCRIPT=' || mailbox.autopagescript)
  374.  
  375.         call writeln(handle, 'AUTOALERTB=' || mailbox.autoalertb)
  376.         call writeln(handle, 'AUTOALERTONDEMAND=' || mailbox.autoalertondemand)
  377.         call writeln(handle, 'AUTOALERTSCRIPT=' || mailbox.autoalertscript)
  378.  
  379.         call close(handle)
  380.     end
  381.  
  382.     return
  383.  
  384. stdabort:
  385. exit
  386.  
  387. stdbusy:
  388. exit
  389.  
  390. stderror:
  391. exit
  392.  
  393. stdtimedout:
  394. exit
  395.  
  396. stdfaxinstruct:
  397. 'playvoice' 'avm:voices/FaxStarting'
  398. action = rc
  399. select
  400.   when action = 0 then nop
  401.   when action = 1 then do; call checkifabort; end
  402.   when action = 4 then nop
  403.   when action = 5 then nop
  404.   when action = 8 then signal stdbusy
  405.   when action = 12 then signal stdabort
  406.   when action = 14 then nop
  407.   when action = 16 then nop
  408.   otherwise signal arexxerror
  409. end
  410.  
  411. stdfax:
  412. faxscript = getclip(address() || 'FAXSCRIPT')
  413. if faxscript = '' then faxscript = 'handlefax'
  414. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  415. else address rexx faxscript address() 'anonymous'
  416. exit
  417.  
  418. stddatainstruct:
  419. 'playvoice' 'avm:voices/DataStarting'
  420. action = rc
  421. select
  422.   when action = 0 then nop
  423.   when action = 1 then do; call checkifabort; end
  424.   when action = 4 then nop
  425.   when action = 5 then nop
  426.   when action = 8 then signal stdbusy
  427.   when action = 12 then signal stdabort
  428.   when action = 14 then nop
  429.   when action = 16 then nop
  430.   otherwise signal arexxerror
  431. end
  432.  
  433. stddata:
  434. datascript = getclip(address() || 'DATASCRIPT')
  435. if datascript = '' then datascript = 'handledata'
  436. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  437. else address rexx datascript address()
  438. exit
  439.  
  440. checkifabort:
  441. 'readnkeys' '1' '3'
  442. action = rc
  443. if action = 0 then value = result
  444. select
  445.   when action = 0 then do; if value = '*' then signal stdabort; end
  446.   when action = 4 then nop
  447.   when action = 5 then nop
  448.   when action = 8 then signal stdbusy
  449.   when action = 10 then nop
  450.   when action = 12 then signal stdabort
  451.   when action = 14 then signal stderror
  452.   when action = 16 then signal stderror
  453.   otherwise signal arexxerror
  454. end
  455. return
  456.  
  457.  
  458.